home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Essential Home & Business Collection
/
The Essential Home & Business Collection.iso
/
27
/
3
/
5
/
HP22D5.ZIP
/
EXTERN
/
TEST.C
< prev
next >
Wrap
Text File
|
1991-04-16
|
6KB
|
209 lines
/*
** test.c: This C source code contains some examples of how
** extensions can be used from HPAD
**
** To make the extension:
**
** C> make test <run the make file>
**
** The make file performs the following compile/link steps:
**
** C> cl /Alfw /c /Oalt /Gs test.c
**
** - /Al use the large memory model
** - /Af use far code pointers
** - /Aw assume SS is not equal to DS (extensions share HPAD's stack)
** - /c compile only in this step
** - /Gs no stack checking (extensions CANNOT perform stack checking)
**
** C> link test,,,startup/NOE;
**
** - /NOE means no default library (extension use a custom printf,sprintf)
*/
#include <dos.h>
#include <stdarg.h> /* include for variable number of arguments */
#include "extern.h" /* Extensions need these! */
/*
** WhenLoaded(): This function gets called immediately after the EXE
** has been relocated in HPAD's memory space. It can
** perform such tasks such as initializing memory space,
** taking over any interrupts, etc. It cannot send
** any messages to HPAD!
**
** Parameters: none
**
** returns: none
**
** notes: If you don't use this function, you don't need to
** include it
**
*/
pascal far WhenLoaded()
{
}
/*
** WhenLoaded(): This function gets called immediately after the EXE
** has been relocated in HPAD's memory space. It can
** perform such tasks such as freeing memory space,
** setting interrupts back, etc. It cannot send
** any messages to HPAD!
**
** Parameters: none
**
** returns: none
**
** notes: If you don't use this function, you don't need to
** include it
*/
pascal far WhenUnLoaded()
{
}
/*
** SampleHandler(): This is a sample handler that is callable from HPAD.
** It demonstrates some of the capabilities of extensions.
**
** Parameters: Variable. This function just prints out any parameters
** that get passed.
**
** returns: STOP = means that this message should not get passed
** on to the next layer in the object heirarchy.
**
** Example: handler select;
** begin
** SampleHandler 1,"Hello","World";
** end;
*/
SampleHandler(int NumArgs,...)
{
va_list args;
HANDLE hdl;
int i;
/* set up 'args' to point to the first argument... */
va_start(args,NumArgs);
/*
/* cycle through the arguments, printing out their values...
** This will mess up the screen, but won't hurt anything!
** NOTE: HPAD takes care of freeing its passed parameters.
*/
for (i=0;i<NumArgs;i++) {
hdl = va_arg(args,HANDLE);
printf("parameter %d = %s\n",i,*hdl);
}
/*
** send a message to HPAD to beep twice. This is done by converting
** a string (the beep command) to a handle in HPAD's memory space.
** then, the new handle is send to HPAD's message dispatcher through
** a function called Do().
** After Do() returns, we free the handle (This is important because
** if the handle is not freed, the memory will be lost forever).
*/
hdl = stoh("beep 2");
Do(hdl);
FreeHandle(hdl);
/*
** Get the contents of a field. This is done by calling GetFieldNum()
** which returns the contents of the Nth field. Again, this function
** returns a handle of a duplicate of the field's content. It is up
** to us to free the handle when we are done.
*/
hdl = GetFieldNum( TRUE, /* it is a field on the page */
1 /* which field (first field) */
);
/* print out the field's content, if there is a content */
if (hdl) {
printf("field 1 = %s\n",*hdl); /* print it */
FreeHandle(hdl); /* free the memory */
}
/*
** Set the content of background field 1. This is done by first
** creating a handle that is to become the field's content. Then
** passing it to HPAD along with which background field we want.
*/
hdl = stoh("This is the new content");
SetFieldNum( FALSE, /* this is a background field */
1, /* set field number 1 */
hdl /* set to this handle */
);
/* this causes HPAD not to pass the message on */
return(STOP);
}
/*
** NumChars(): This is a sample function that count the occurrences of
** a character in a string.
**
** Parameters: SearchCh: The character we are counting
** SearchStr: The string we are searching
**
** returns: Count: The number of occurrences of SearchCh
** in the string SearchStr
**
** Example: handler select;
** begin
** -- this will put 2 into the message box
** put the NumChars of "o","Hello world";
** end;
**
*/
NumChars(int NumArgs,...)
{
va_list args;
HANDLE hdl;
int count,SearchCh;
char *SearchStr;
/* check for invalid number of arguments */
if (NumArgs != 2) return(STOP);
/* set up 'args' to point to the first argument... */
va_start(args,NumArgs);
/* get the search character */
SearchCh = **va_arg(args,HANDLE);
/* get a pointer to the search string */
SearchStr = *va_arg(args,HANDLE);
/* perform the search */
for (count=0;*SearchStr;SearchStr++)
if (*SearchStr == SearchCh) count++;
/* call integer-to-handle (itoh) to return the value to HPAD */
ReturnValue(itoh(count));
/* don't pass the message on */
return(STOP);
}
POOL pascal Pool[] = {
{ "Sample", /* name of the handler */
SampleHandler, /* pointer to the handler */
0, /* reserved */
HANDLER}, /* this is a handler, not a function */
{ "NumChars", /* name of this function */
NumChars, /* pointer to this function */
0, /* reserved */
FUNCTION}, /* this is a function */
{ NULL, /* NULLs signify the end of the table */
NULL,
0,
0} };